package com.zl.tcbnewcar.utils;

import java.text.DecimalFormat;

/**
 * Created by Administrator on 2018\1\15 0015.
 */

public class DoubleUtils {

    public static double format0_00(double d) {
        DecimalFormat df = new DecimalFormat("######0.00");
        String format = df.format(d);
        return Double.parseDouble(format);
    }


    public static Double format0_00(String d) {
        DecimalFormat df = new DecimalFormat("######0.00");
        String format = df.format(d);
        return Double.parseDouble(format);
    }

    /**
     *我已经做了用户输入限制，但是如果有人就是找茬输入了小数点不输入后面小数怎么办
     *这里加一个判断如果小数点后没有内容，我们就将小数点去掉
     */
    public static Double handleData(String number) {
        double i;
        if (number.contains(".")) {
            int index = number.lastIndexOf(".");
            if (index == (number.length() - 1)) {
                i = Double.parseDouble(number.replaceAll("\\.", ""));
            } else {
                i = Double.parseDouble(number);
            }
        } else {
            i = Double.parseDouble(number);
        }
        return i;
    }

}
